﻿using BCCommon;
using BCDto.TMS.Agent.AgentCurrentlyProtocol;
using BCService.TMS.Agent.AgentCurrentlyProtocol;
using BCTMSRESTful.Configs;
using BCTMSRESTful.Controllers.Management;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace BCTMSRESTful.Controllers.Management.Agent
{
    /// <summary>
    /// 代理商现行协议
    /// </summary>
    [ApiExplorerSettings(GroupName = "Admin")]
    [Route("api/v1/sim/[controller]")]
    public class AgentCurrentlyProtocolController : ManagementBaseController
    {
        private readonly IAgentCurrentlyProtocolService agentCurrentlyProtocolService;

        public AgentCurrentlyProtocolController(IAgentCurrentlyProtocolService agentCurrentlyProtocolService)
        {
            this.agentCurrentlyProtocolService = agentCurrentlyProtocolService;
        }

        /// <summary>
        /// 添加代理商现行协议
        /// </summary>
        /// <param name="agentRecordId">代理商记录Id</param>
        /// <param name="requestDto">代理商现行协议信息</param>
        /// <response code="201">添加代理商现行协议</response>
        /// <returns></returns>
        [HttpPost("{agent_record_id}")]
        [Log("添加代理商现行协议")]
        [ProducesResponseType(typeof(AgentCurrentlyProtocolDto), 201)]
        public IActionResult Post([FromRoute(Name = "agent_record_id")]long agentRecordId,
            [FromBody] AgentCurrentlyProtocolRequestDto requestDto)
        {
            var result = this.agentCurrentlyProtocolService.Add(this.Admin, agentRecordId, requestDto);
            return this.Ok(result);
        }

        /// <summary>
        /// 修改代理商现行协议
        /// </summary>
        /// <param name="agentCurrentlyProtocolId">代理商现行协议Id</param>
        /// <param name="requestDto">代理商现行协议信息</param>
        /// <response code="200">修改代理商现行协议</response>
        /// <returns></returns>
        [HttpPut("{agent_currently_protocol_id}")]
        [Log("修改代理商现行协议")]
        [ProducesResponseType(typeof(AgentCurrentlyProtocolDto), 200)]
        public IActionResult Put([FromRoute(Name = "agent_currently_protocol_id")] long agentCurrentlyProtocolId,
            [FromBody] AgentCurrentlyProtocolRequestDto requestDto)
        {
            var result = this.agentCurrentlyProtocolService.Update(this.Admin, agentCurrentlyProtocolId, requestDto);
            return this.Ok(result);
        }

        /// <summary>
        /// 删除代理商现行协议
        /// </summary>
        /// <param name="agentCurrentlyProtocolId">代理商现行协议Id</param>
        /// <response code="204">删除代理商现行协议</response>
        /// <returns></returns>
        [HttpDelete("{agent_currently_protocol_id}")]
        [Log("删除代理商现行协议")]
        [ProducesResponseType(typeof(NoContentResult), 204)]
        public IActionResult Put([FromRoute(Name = "agent_currently_protocol_id")] long agentCurrentlyProtocolId)
        {
            this.agentCurrentlyProtocolService.Delete(this.Admin, agentCurrentlyProtocolId);
            return NoContent();
        }

        /// <summary>
        /// 获取代理商现行协议
        /// </summary>
        /// <param name="signStartDate">签署开始日期</param>
        /// <param name="signEndDate">签署结束日期</param>
        /// <param name="pageIndex">页号</param>
        /// <param name="pageSize">每页数据条数</param>
        /// <response code="200">获取代理商现行协议</response>
        /// <returns></returns>
        [HttpGet]
        [ProducesResponseType(typeof(PageableList<AgentCurrentlyProtocolDto>), 200)]
        public IActionResult Query([FromQuery(Name = "sign_start_date")]DateTime? signStartDate,
            [FromQuery(Name = "sign_end_date")]DateTime? signEndDate,
            [FromQuery(Name = "page_index")]int pageIndex = 1,
            [FromQuery(Name = "page_size")]int pageSize = 10)
        {
            var result = this.agentCurrentlyProtocolService.Query(this.Admin, signStartDate, signEndDate, pageIndex, pageSize);
            return this.Ok(result);
        }

        /// <summary>
        /// 获取单个代理商现行协议
        /// </summary>
        /// <param name="agentRecordId">代理商记录Id</param>
        /// <response code="200">获取单个代理商现行协议</response>
        /// <returns></returns>
        [HttpGet("[action]/{agent_record_id}")]
        [ProducesResponseType(typeof(AgentCurrentlyProtocolDto), 200)]
        public IActionResult Single([FromRoute(Name = "agent_record_id")] long agentRecordId)
        {
            var result = this.agentCurrentlyProtocolService.QuerySingle(agentRecordId);
            return this.Ok(result);
        }
    }
}
